﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using AopAndIocDemo.Biz.Aspect;

namespace AopAndIocDemo.WebUI.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        [TimmingAspect]
        [LogAspect("HomeController fadeIn", "fadeOut", false)]
        [ExceptionAspect]
        public ActionResult Index()
        {
            ViewBag.Tips = "hello world.";
            ViewBag.Msg = Download();

            string s = "sss";

            return View();
        }

        [ExceptionAspect]
        public ActionResult GetList(int id)
        {
            double d = 100/id; //测试ExceptionAspect
            var data = new {id = id, msg = "success."};


            return Json(data, JsonRequestBehavior.AllowGet);
        }

        public async Task<string> Download()
        {
            string url = "http://www.baidu.com";
            HttpClient client = new HttpClient();
            //client.BaseAddress = new Uri(url);

            return await client.GetStringAsync(url);
        }
    }
}